package org.qpcr.community.project.web;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.QueryAction;
import org.hswebframework.web.authorization.annotation.Resource;
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
import org.qpcr.community.device.entity.vo.DeviceInstanceVo;
import org.qpcr.community.project.model.entity.DataGroupEntity;
import org.qpcr.community.project.model.entity.ExperimentalRecordsInstanceEntity;
import org.qpcr.community.project.response.DataGroupDetail;
import org.qpcr.community.project.service.DataGroupService;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import lombok.Data;

@RestController
@RequestMapping({"/project/data-group", "/project/data/group"})
@Authorize(ignore = true)
@Resource(id = "data-group", name = "数据分组记录")
@Slf4j
@Tag(name = "数据分组记录接口")
@RequiredArgsConstructor
public class DataGroupController implements
    ReactiveServiceCrudController<DataGroupEntity, String> {

    @Getter
    private final DataGroupService service;

    /**
     * 修改分组名称
     */
    @PutMapping("/update-name")
    @QueryAction
    @Authorize(ignore = true)
    public Mono<Integer> updateName(@RequestBody DataGroupEntity entity) {
        return service.updateNameById(entity.getId(), entity.getName());
    }

    @GetMapping("{id}/detail")
    @QueryAction
    @Authorize(ignore = true)
    public Mono<DataGroupDetail> getDetailById(@PathVariable("id") String id) {
        return service.getDetailById(id);
    }



    @PostMapping("query-with-data-count")
    @QueryAction
    @Authorize(ignore = true)
    public Mono<PagerResult<DataGroupDetail>> queryPagerWithDataCount(@RequestBody QueryParamEntity query) {
        return this.service.queryPagerWithDataCount(query);
    }
}
